package priv.bruce.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import priv.bruce.entry.AdvertisingInfo;
import priv.bruce.service.AdvertisingServise;
import priv.bruce.service.MovieInfoService;

public class AddAdvertiseServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	private AdvertisingServise advertisingServise = new AdvertisingServise();

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("application/json;charset=utf-8");
		String adName = request.getParameter("ad_name");
		String adPath = request.getParameter("ad_path");
		double pay = Double.valueOf(request.getParameter("ad_money"));
		String picture = request.getParameter("ad_picture");
		try {
			List<AdvertisingInfo> list = advertisingServise.findADByName(adName);
			if (list.size() > 0) {
				if (list.get(0).getAdName().equals(adName)) {
					response.getWriter().append(JSON.toJSONString(-1));
				}
			}else {
				int addAD = advertisingServise.addAD(adName, adPath, pay, picture);
				System.out.println("影响行数："+addAD);
				response.getWriter().append(JSON.toJSONString(addAD));
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
